Skip to content

fix(token): verify JWT algorithm in parse keyfunc [H1]#550

Merged
lakhansamani merged 1 commit intomainfrom
fix/h1-jwt-algorithm-verify
Apr 4, 2026
Merged

fix(token): verify JWT algorithm in parse keyfunc [H1]#550
lakhansamani merged 1 commit intomainfrom
fix/h1-jwt-algorithm-verify

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

Summary

  • H1 (High): Keyfunc never validated token.Method — textbook JWT algorithm confusion vulnerability
  • Now verifies token signing method matches configured JWTType in all three keyfunc branches (HMAC, RSA, ECDSA)

Test plan

  • Package compiles
  • Verify tokens signed with correct algorithm still validate
  • Verify tokens with mismatched algorithm are rejected

The keyfunc never validated token.Method against the expected signing
method, enabling JWT algorithm confusion attacks where an attacker
could craft a token using a different algorithm (e.g., HMAC with the
public key as secret) to bypass signature verification.

Now each keyfunc verifies the token's algorithm matches the configured
signing method before returning the verification key.

Fixes: H1 (High)
@lakhansamani lakhansamani merged commit 7b91b21 into main Apr 4, 2026
@lakhansamani lakhansamani deleted the fix/h1-jwt-algorithm-verify branch April 4, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant